import request from '@/assets/utils/request'

/**
  * 根据学科名称获取学科列表
  */
export const getSubjectList = subjectName => {
  if (!subjectName) subjectName = ''
  return request({
    url: '/subjects/simple/' + subjectName,
    method: 'GET'
  })
}

/**
  * 根据学科ID获取目录列表
  */
export const getCatalogList = subjectID => {
  return request({
    url: '/directorys',
    method: 'GET',
    query: {
      subjectID
    }
  })
}

/**
  * 获取企业列表
  */
export const getCompanyList = () => {
  return request({
    url: '/companys',
    method: 'GET'
  })
}

/**
  * 获取方向列表
  */
export const getDirectionList = () => {
  return request({
    url: '/questions',
    method: 'GET',
  })
}

/**
  * 根据学科ID获取标签列表
  */
export const getTagsList = subjectID => {
  return request({
    url: '/tags',
    method: 'GET',
    query: {
      subjectID
    }
  })
}

/**
  * 根据学科名称获取学科列表
  */
export const getSubjectInfo = subjectID => {
  return request({
    url: '/subjects/' + subjectID,
    method: 'GET'
  })
}

/**
  * @description:获取基础/精选题库列表
  */
export const getBaseQuesList = (params, choice) => {
  choice = choice ? '/choice' : ''
  return request({
    url: '/questions' + choice,
    method: 'GET',
    params
  })
}
// 获取详细数据
export const getSubjectManage = params => {
  return request({
    url: '/subjects',
    method: 'GET',
    params
  })
}
// 请求添加数据
export const postSubject = data => {
  return request({
    url: '/subjects',
    method: 'POST',
    data
  })
}
// 修改学科数据
export const xiugaiSubject = data => {
  return request({
    url: '/subjects/' + data.id,
    method: 'PUT',
    data
  })
}
// 删除学科
export const deleteSubject = id => {
  return request({
    url: '/subjects/' + id,
    method: 'DELETE',
  })
}

/**
  * @description:根据试题ID删除试题
  */
export const delBasicsQues = id => {
  return request({
    url: '/questions/' + id,
    method: 'DELETE'
  })
}

/**
  * @description:根据试题ID加入/删除精选
  */
export const choiceQues = (id, choiceState) => {
  if (choiceState === undefined) {
    choiceState = 1
  }
  return request({
    url: `/questions/choice/${id}/${choiceState}`,
    method: 'PATCH'
  })
}

/**
  * @description:根据试题ID上架/下架
  */
export const publishQues = (id, publishState) => {
  if (!publishState) {
    publishState = 1
  }
  return request({
    url: `/questions/choice/${id}/${publishState}`,
    method: 'POST'
  })
}

/**
  * @description: 试题审核
  */
export const auditQues = (id, chkState, chkRemarks) => {
  return request({
    url: '/questions/check/' + id,
    method: 'POST',
    data: {
      id, chkState: parseInt(chkState), chkRemarks
    }
  })
}

/**
  * @description: 新增试题
  */
export const entryQues = data => {
  return request({
    url: '/questions',
    method: 'POST',
    data
  })
}

/**
  * @description: 获取试题
  */
export const getQues = id => {
  return request({
    url: `/questions/${id}`,
    method: 'GET'
  })
}

/**
  * @description: 修改试题
  */
export const editQues = (id, data) => {
  return request({
    url: `/questions/${id}`,
    method: 'PUT',
    data
  })
}
